﻿//----------------------------------------------------------------
// <copyright file="TheService.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//----------------------------------------------------------------

using System;
using System.Configuration;
using System.Diagnostics;

namespace MptCodeLibrary.Exceptions
{
    public class MptEventLogger
    {
        private const string source = "Microsoft Process Template";
        private const string log = "Application";

        public static void WriteTrace(string message)
        {
            InitializeEventSource();

            if (string.Equals(ConfigurationManager.AppSettings["DebugTraceEnabled"], "true", StringComparison.OrdinalIgnoreCase))
                EventLog.WriteEntry(source, message, EventLogEntryType.Information);
        }

        public static void WriteError(string message)
        {
            InitializeEventSource();

            EventLog.WriteEntry(source, message, EventLogEntryType.Error);
        }

        private static void InitializeEventSource()
        {
            if (!EventLog.SourceExists(source))
                EventLog.CreateEventSource(source, log);
        }
    }
}
